package com.springboot.controller;

import com.alibaba.fastjson.JSONObject;
import com.springboot.util.WXPaymentTool;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.UUID;

/**
 * @Author: TongRui乀
 * @Date: 2019/6/27 13:39
 * @description：
 */
@RestController
@RequestMapping("wx")
public class WxController {


    @GetMapping("pay")
    public JSONObject testWxPay(){

        JSONObject result = new JSONObject();
        try {

            SortedMap<Object, Object> parameters = new TreeMap<Object, Object>();
            parameters.put("appid", "wx945bedf330bd40a4");
            parameters.put("mch_id", "1532517381");
            parameters.put("nonce_str", UUID.randomUUID().toString().replaceAll("-", ""));
            parameters.put("body", "永成医美-订单支付");
            parameters.put("spbill_create_ip", "114.250.150.10");
            parameters.put("notify_url", "https://text.tyc-bj.cn/yc/api/shopp/payment/payNotify");
            parameters.put("trade_type", "JSAPI");
            Double ceil = Math.ceil(Math.random() * 1000000);
            parameters.put("out_trade_no", ceil.intValue());
            parameters.put("total_fee", 100);
            parameters.put("openid", "o0LFo5LqM5aKseKd_li5PH6_ba0I");

            result = WXPaymentTool.requestPayment(parameters, "U3pFoGx1i3sclqNbx2LH8aoSJmV29901");

        } catch (Exception e) {
            e.printStackTrace();
            result.put("code", 500);
            result.put("message", e.getLocalizedMessage());
        }
        return result;
    }

}
